package com.sky.controller.user;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.Result;
import com.sky.service.IDishService;
import com.sky.service.ISetmealDishService;
import com.sky.service.ISetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 套餐 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-22
 */
@RestController
@RequestMapping("/user/setmeal")
@Slf4j
@Api(tags = "用户端-套餐相关接口")
@RequiredArgsConstructor
public class SetmealController {
    private final ISetmealService setmealService;
    private final IDishService dishService;
    private final ISetmealDishService setmealDishService;
    private final RedisCacheManager cacheManager;

    @ApiOperation("根据分类id查询套餐")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    public Result<List<Setmeal>> listByCategoryId(Long categoryId) {
        List<Setmeal> list = setmealService.lambdaQuery()
                .eq(categoryId!=null,Setmeal::getCategoryId, categoryId)
                .list();
        return Result.success(list);
    }

    @ApiOperation("根据套餐id查询包含的菜品")
    @GetMapping("/dish/{id}")
    @Cacheable(cacheNames = "dish", key = "#id")
    public Result<List<DishItemVO>> listBySetmealId(@PathVariable Long id) {
        List<DishItemVO> list = setmealService.getDishItemById(id);
        return Result.success(list);
    }
}
